package com.sc.nft.entity.vo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.sc.nft.exception.GlobalRunTimeException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;
@Data
public class BatchEnterIntegrationShowVO {

    @ApiModelProperty("用户数据信息")
    private List<BatchEnterIntegrationShowListVO> list;


    /**
     * 前置验证,判定是否有手机号为空的存在
     * @param voList
     * @return
     */
    public  void  prepositionVerify(List<BatchEnterIntegrationShowListVO> voList) {
        List<BatchEnterIntegrationShowListVO> collect = voList.stream().filter(batchEnterIntegrationShowListVO -> StrUtil.isBlank(batchEnterIntegrationShowListVO.getUserTel())).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(collect)) {
            throw new GlobalRunTimeException("手机号不能为空");
        }
    }


    public List<BatchEnterIntegrationShowListVO> compare(List<BatchEnterIntegrationShowListVO> voList,List<BatchEnterIntegrationShowListVO>userInfoList){
        // voList和userInfoList的userTel差集
        List<BatchEnterIntegrationShowListVO> collect = voList.stream().filter(batchEnterIntegrationShowListVO -> !userInfoList.stream().map(BatchEnterIntegrationShowListVO::getUserTel).collect(Collectors.toList()).contains(batchEnterIntegrationShowListVO.getUserTel())).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(collect)) {
         throw new GlobalRunTimeException(StrUtil.format("多手机号重复或不存在,验证后请重新上传!手机号:{}",collect.stream().map(BatchEnterIntegrationShowListVO::getUserTel).collect(Collectors.joining(","))));
        }
        // 把voList的用户信息和userInfoList的用户信息进行匹配,计算积分
        userInfoList.forEach(batchEnterIntegrationShowListVO -> {
            BatchEnterIntegrationShowListVO data = voList.stream().filter(voListResult -> voListResult.getUserTel().equals(batchEnterIntegrationShowListVO.getUserTel())).findFirst().get();
            batchEnterIntegrationShowListVO.setControlsTokenNum(data.getControlsTokenNum());
        });
        return userInfoList;
    }

}
